/*

Copyright 2006 Renaun Erickson (http://renaun.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@ignore
*/
package com.renaun.rpc {

	import flash.net.NetConnection;
	import flash.net.ObjectEncoding;
	import mx.core.Application;
	import com.nstar.base.event.ConnectStatusEvent;
	import com.nstar.components.ErrorView;
	import flash.events.NetStatusEvent;

	public class RemotingConnection extends NetConnection
	{
		public function RemotingConnection( sURL:String )
		{
			objectEncoding = ObjectEncoding.AMF0;
			//增加网络异常时的处理
			this.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);			
			if (sURL) connect( sURL );
		}
		
		public function AppendToGatewayUrl( s : String ) : void
		{
			//
		}

        public function AddHeader() : void
        {
        }
        
        public function ReplaceGatewayUrl() : void
        {
        }

		//处理网络连接状态的事件，如网络不通
		public function netStatusHandler(event:NetStatusEvent):void{
			//在应用层广播事件，可以在应用处理这个事件，如需要隐藏进度条的加载
			var app:* = Application.application;
			app.dispatchEvent(new ConnectStatusEvent(event.info));
			//同时在这里直接显示异常信息
			ErrorView.showErrorView(event.info);
		}
        
		
	}
}

